/// General Binary Tag System
module jinji.tag.model;

import jinji.common.model;

/// 默认标签类别
enum defCategory = cast(Name)"general";

/// 标签
@snakeCase
struct Tag {
@notnull:
	/// 标签ID
	@serial Id id;
	/// 标签名
	@unique TagName name;
	/// 标签类别
	@FK!(TagCategory.name) Name category = defCategory;
	/// 标签组
	@defEmpty Tags group;
	/// 使用的帖子数
	@default0 long count;
	mixin timeInfo;
}

/// 标签别名
@snakeCase
struct TagAlias {
@notnull:
	/// 标签别名ID
	@serial Id id;
	/// 别名
	@unique TagName name;
	/// 原名
	Tags to;
	/// 描述
	@defEmpty @descT Desc desc;
	mixin timeInfo!true;
}

/// 隐含标签
@snakeCase
struct TagImplications {
@notnull:
	/// 隐含标签ID
	@serial Id id;
	/// 原名
	@unique @nameT TagName name;
	/// 暗示的标签
	Tags tags;
	/// 描述
	@defEmpty @descT Desc desc;
	mixin timeInfo!true;
}

/// 标签互斥组
@snakeCase
struct TagGroup {
@notnull:
	/// 标签互斥组ID
	@serial Id id;
	/// 名称
	@unique @nameT Name name;
	/// 描述
	@defEmpty @descT Desc desc;
	mixin timeInfo!true;
}

/// 标签类别
@snakeCase
@noRowid struct TagCategory {
	/// 名称
	@notnull @PK @nameT Name name;
	/// 父类别
	@FK!name @nameT Name parent;
@notnull:
	/// 描述
	@defEmpty @descT Desc desc;
	/// 样式
	@defEmpty @descT Desc style;
	mixin timeInfo!true;
}

/// 标签别名可见性
@snakeCase
struct TAVisibility {
@notnull:
	/// 标签别名ID
	@PK @FK!(TagAlias.id) Id id;
	mixin Visibility;
}

/// 标签互斥组可见性
@snakeCase
struct TGVisibility {
@notnull:
	/// 标签互斥组ID
	@PK @FK!(TagGroup.id) Id id;
	mixin Visibility;
}

/// 隐含标签可见性
@snakeCase
struct TIVisibility {
@notnull:
	/// 隐含标签ID
	@PK @FK!(TagImplications.id) Id id;
	mixin Visibility;
}

/// 标签数增量
@snakeCase
@noRowid struct TagCountDelta {
@notnull:
	/// 标签名
	@PK TagName name;
	/// 增量
	long delta;
}
